package com.xyz.init;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import org.springframework.context.ApplicationContext;

import com.xyz.business.service.ConfigService;
import com.xyz.business.service.UserService;
import com.xyz.init.infos.ConfigInit;
import com.xyz.init.infos.UserInfosInit;

/**
 * 加载系统信息
 * 
 * @author xyzjh
 * 
 */
public class XYZListener implements ServletContextListener {

	@Override
	public void contextDestroyed(ServletContextEvent arg0) {

	}

	/**
	 * 系统初始化 (non-Javadoc)
	 * 
	 * @see javax.servlet.ServletContextListener#contextInitialized(javax.servlet.ServletContextEvent)
	 */
	@Override
	public void contextInitialized(ServletContextEvent arg0) {
		ApplicationContext context = XYZContext.getApplicationContext();
		// 加载用户信息
		initUserInfos(context);
		iniConfigInfos(context);
	}

	private void initUserInfos(ApplicationContext context) {
		UserService userService = (UserService) context.getBean("userService");
		UserInfosInit.init(userService);
	}

	private void iniConfigInfos(ApplicationContext context) {
		ConfigService configService = (ConfigService) context
				.getBean("configService");
		ConfigInit.init(configService);
	}

}
